package com.winspread.app_30

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Toast

import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity : io.flutter.embedding.android.FlutterActivity() {

    private val SHARE_CHANNEL = "channel:Chenli"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
        MethodChannel(
            flutterEngine.dartExecutor,
            SHARE_CHANNEL
        ).setMethodCallHandler { methodCall, result ->
            if (methodCall.method == "openWechat") {
                print("-------- ${methodCall.method}")
                shareFile()
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    private fun shareFile() {
        try {
            val url = "weixin://"
            startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
        } catch (e: Exception) {
            Toast.makeText(this, "无法跳转到微信，请检查您是否安装了微信！", Toast.LENGTH_SHORT).show()
        }
    }
}